<?php
defined( '_VALID_MOS' ) or die('<script>window.location.href="http://www.kinifurniture.com";</script>');

$adm_functions->is_admin_login();
if(!$coll)
$coll='all';

$icon_description='
<table><tr><td>
	<table cellspacing="0" cellpadding="4" border="0" align="center">
		<tr align="center">
			<td>
				<img src="show_files/tick.png" border="0" alt="Pending" />
			</td>
			<td>
				Product is <u>FSC Labeled</u> or <u>Sample</u> product  |
			</td>
			<td>
				<img src="show_files/publish1.png" border="0" alt="Visible" />
			</td>
			<td>
				Product is <u>not FSC Labeled</u> or <u>not for Sample</u>  |
			</td>
			<td>
				<img src="show_files/delete.png" border="0" alt="Visible" />
			</td>
			<td>
				<u>Delete</u> Product
			</td>
		</tr>
	</table>
</td></tr><tr><td align="center">
	<table cellspacing="0" cellpadding="4" border="0" align="center">
		<tr align="center">
			<td align="center">
				<i>Click on icon to toggle state or execute command.</i>
			</td>
		</tr>
	</table>
</td></tr></table>
';
$adm_menu='
<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
<tr>
	<td class="menudottedline" width="40%">
		<div class="pathway"><img border="0" src="assets/admin/'.$SITE_LOGO_ADMIN.'"/></div>	</td>
	<td class="menudottedline" align="right">
		<table cellpadding="0" cellspacing="0" border="0" id="toolbar">
			<tr valign="middle" align="center">
				<td>&nbsp;</td>
				<td>
					<a class="toolbar" href="admin.php?show=index">
					<img src="show_files/home.png" alt="Home" name="home" title="Home" align="middle" border="0" />				<br />Home</a>
				</td>
				<td>&nbsp;</td>
				<td>
					<a class="toolbar" href="admin.php?show=collection_manager">
					<img src="show_files/back.png"  alt="Collections" name="collection" title="Collections" align="middle" border="0" /><br />Collections</a>
				</td>
				<td>&nbsp;</td>
				<td>
					<a class="toolbar" href="admin.php?show=add_product&coll='.$coll.'">
					<img src="show_files/new_f200.png"  alt="New" name="new" title="New" align="middle" border="0" />				<br />New</a>
				</td>
			</tr>
		</table>
	</td>
</tr>
</table>

<br />
';
if($action=="do_sample"){
	$dbh->query("update produk set sample='Y' where product_id=$id");
	echo '<script>window.location.href="admin.php?show=product_manager&coll='.$coll.'";</script>';
}
if($action=="do_unsample"){
	$dbh->query("update produk set sample='N' where product_id=$id");
	echo '<script>window.location.href="admin.php?show=product_manager&coll='.$coll.'";</script>';
}
if($action=="do_fsc"){
	$dbh->query("update produk set fsclabel='Y' where product_id=$id");
	echo '<script>window.location.href="admin.php?show=product_manager&coll='.$coll.'";</script>';
}
if($action=="do_unfsc"){
	$dbh->query("update produk set fsclabel='N' where product_id=$id");
	echo '<script>window.location.href="admin.php?show=product_manager&coll='.$coll.'";</script>';
}
if($action=="do_delete"){
	$qrydel="select * from produk where product_id=$id";
	$selectdel=$dbh->query($qrydel);
	while($sqldel=mysql_fetch_object($selectdel))
	{
		$img_name=$sqldel->imglarge;
		$idkoleksi=$sqldel->koleksi;
		if ($img_name!='')
		@unlink("assets/product/".$img_name);
		$dbh->query("delete from produk where product_id=$id");
		echo '<script>window.location.href="admin.php?show=product_manager&coll='.$coll.'";</script>';
	}
}
if($action=="") $action="list";

if($action=="list"){

if(!$page_no)
	$page_no=1;
$MAX=10;
$lastrow=$MAX+$page_no;
if(!next_page)
	$next_page=1;
$next_page=$next_page+1;

$imgSr=$page_no;


$selected='';

if($coll=='all')
{
	$condition="";
	$selected='selected';
} else {
	$condition="where koleksi=".$coll;
}

	$sort_koleksi='
		<select name="coll" class="inputbox" size="1" onchange="document.adminForm.submit();">
			<option value="all" '.$selected.'>All</option>';

	$qrykoleksi="select * from koleksi";
	$selectkoleksi=$dbh->query($qrykoleksi);
	while($sqlRowkoleksi=mysql_fetch_object($selectkoleksi))
	{
		$id_koleksi=$sqlRowkoleksi->id;
		$nama_koleksi=$sqlRowkoleksi->nama;
		if($id_koleksi==$coll) 
		{ 
			$selected=' selected';
			$section=$sqlRowkoleksi->nama;
		} 
		else $selected='';
		$sort_koleksi.='<option value="'.$id_koleksi.'" '.$selected.'>'.$nama_koleksi.'</option>';
	}
	if($section=='') $section='All';

	$sort_koleksi.='</select>';
		
	$qry="select * from produk $condition";
	$lim_min = ($page_no-1)*$MAX;
	$qry2="$qry limit $lim_min,$MAX"; 
	$select=$dbh->query($qry2);
	$TOTAL_RECORDSET=$dbh->num_rows($dbh->query($qry));

	$produk_list='';
	$nomor_urut=(($page_no-1)*$MAX);
	while($sqlRow=mysql_fetch_object($select))
	{
	$nomor_urut++;
	$id_produk=$sqlRow->product_id;
	$nr_produk=$sqlRow->nr;
	$id_koleksi=$sqlRow->koleksi;
	$nama_produk=$sqlRow->nama_produk;
	$deskripsi=$sqlRow->keterangan;
	$thumbnail=$sqlRow->imglarge;
	$size=$sqlRow->size;
	if ($sqlRow->sample=='Y') 
			$sample="<a href='admin.php?show=product_manager&action=do_unsample&id=$id_produk&coll=$id_koleksi'><img border='0' src='show_files/tick.png' /></a>";
		else 
			$sample="<a href='admin.php?show=product_manager&action=do_sample&id=$id_produk&coll=$id_koleksi'><img border='0' src='show_files/publish1.png' /></a>";
	if ($sqlRow->fsclabel=='Y') 
			$urlfsc="<a href='admin.php?show=product_manager&action=do_unfsc&id=$id_produk&coll=$id_koleksi'><img border='0' src='show_files/tick.png' /></a>";
		else 
			$urlfsc="<a href='admin.php?show=product_manager&action=do_fsc&id=$id_produk&coll=$id_koleksi'><img border='0' src='show_files/publish1.png' /></a>";
	if ($thumbnail=='') $thumbnail='noimg.png';
	$thumbnail="<a href='admin.php?show=edit_product&id=$id_produk&coll=$coll'><img border='0' width='75' height='56' src='assets/product/$thumbnail' /></a>";
	$product_list.='
		<tr class="row0">
			<td align="center">
				'.$nomor_urut.'
			</td>
			<td align="left">
				'.$nr_produk.'
			</td>
			<td align="left">
				'.$thumbnail.'
			</td>
			<td>
				'.$size.'
			</td>
			<td>
				'.$nama_produk.'
			</td>
			<td align="center">
				'.$sample.'
			</td>
			<td align="center">
				'.$urlfsc.'
			</td>
			<td align="center">
				<a href="admin.php?show=product_manager&action=do_delete&id='.$id_produk.'" onclick="return confirm(\'Do you want to delete?\');"><img border="0" src="show_files/delete.png" /></a>
			</td>
		</tr>
	';
	}

}

//=====================Starting Pagination From Here==========================
	
	//global $my_page_name;
	$my_page_name="./admin.php?show=product_manager&coll=".$coll;
	include("admin_pagination.inc");

?>